// 标定用来计算批量任务结束时间
let secsDate
// 当前标定快速
var fast
// 当前标定慢速
var slow

var pondStatus = 0;

var ids = [];

var hourJson = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09",
    "10", "11", "12", "13", "14", "15", "16", "17", "18", "19",
    "20", "21", "22", "23"]

var minJson = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09",
    "10", "11", "12", "13", "14", "15", "16", "17", "18", "19",
    "20", "21", "22", "23", "24", "25", "26", "27", "28", "29",
    "30", "31", "32", "33", "34", "35", "36", "37", "38", "39",
    "40", "41", "42", "43", "44", "45", "46", "47", "48", "49",
    "50", "51", "52", "53", "54", "55", "56", "57", "58", "59"
]
var workshopSelect = [];
var specieSelect = [];
var calibrationSelect = [];
var stationTypeSelect = [];
$(function () {
    var workshopId = MX.getQueryVariable("workshopId");
    var status = MX.getQueryVariable("status");
    if (workshopId == null || workshopId === "null") {
        workshopId = "";
    }
    if (status === null) {
        status = "";
    }

    var listUrl = STATION_LIST + "?workshopId=" + workshopId + "&status=" + status;
    Table.builder()
        .listUrl(listUrl)
        .customValidate(check)
        .init();

    function check(validatorDom) {
        if (validatorDom.attr("name") === "name" && validatorDom.val().length > 100) {
            return {
                "retBool": true,
                "msg": "设备名称长度不能超过100个字符"
            };
        }
        if (validatorDom.attr("name") === "poolLong" && validatorDom.val() < 0) {
            return {
                "retBool": true,
                "msg": "养殖池长度(半径)不能小于0"
            };
        }
        if (validatorDom.attr("name") === "poolWidth" && validatorDom.val() < 0) {
            return {
                "retBool": true,
                "msg": "养殖池宽度不能小于0"
            };
        }
        if (validatorDom.attr("name") === "poolHeight" && validatorDom.val() < 0) {
            return {
                "retBool": true,
                "msg": "养殖池高度不能小于0"
            };
        }
        if (validatorDom.attr("name") === "poolVolume" && validatorDom.val() < 0) {
            return {
                "retBool": true,
                "msg": "养殖池体积不能小于0"
            };
        }
    }

    //初始化下拉选
    $("#task_form").find(".select-init").each(function () {
        var that = $(this);
        var html = "";
        html += "<option value=''>请选择</option>"
        Request.builder()
            .url(STATION_ALL_SELECT)
            .isToken(true)
            .callback(function (e) {
                if (e.code === "00000") {
                    workshopSelect = e.workshops;
                    specieSelect = e.species;
                    calibrationSelect = e.calibrations;
                    stationTypeSelect = e.stationTypes;
                    if (workshopSelect.length > 0) {
                        Select.builder()
                            .dom($("#workshopId"))
                            .data(workshopSelect)
                            .initByData();
                    }
                    if (specieSelect.length > 0) {
                        Select.builder()
                            .dom($("#speciesId"))
                            .data(specieSelect)
                            .initByData();
                    }
                    if (stationTypeSelect.length > 0) {
                        Select.builder()
                            .dom($("#typeId"))
                            .data(stationTypeSelect)
                            .initByData();
                    }
                    secsDate = calibrationSelect
                    $.each(calibrationSelect, function (index, item) {
                        html += "<option value='" + item["id"] + "' nsecs='" + item["normalSecs"] + "' hsecs='" + item["highSecs"] + "' id='" + ('calibrationId' + index) + "'>";
                        if (item.showType === 0) {
                            html += "" + item["name"] + "mm" + "—(" + "";
                            if (item.normalValue !== "") {
                                html += item.normalValue + ";";
                            }
                            if (item.highValue !== "") {
                                html += item.highValue + ";";
                            }
                            html += ")" + "</option>";
                        } else {
                            if (item.shortName === "") {
                                html += "" + item["name"] + "mm" + "";
                            } else {
                                html += "" + item["shortName"] + "";
                            }
                        }
                    });
                    that.html(html);
                }
            }).get();
    })

    $("#tableAjaxId").on("click", ".btn_dif_function", function () {
        var dom = $(this).attr("data-target");
        //删除input下方的红字提醒
        if ($(dom).find(".has-error").length > 0) {
            $(dom).find(".has-error").each(function () {
                $(this).removeClass("has-error")
            })
        }
        if ($(dom).find(".help-block").length > 0) {
            $(dom).find(".help-block").each(function () {
                $(this).remove()
            })
        }
    });

    //点击计算体积1
    $("#btn_squaresPond").click(function () {
        var long = document.getElementById("poolLong").value;
        var width = document.getElementById("poolWidth").value;
        var height = document.getElementById("poolHeight").value;
        var volume = document.getElementById("poolVolume");

        volume.value = long * width * height;
    })
    //点击计算体积2
    $("#btn_circlesPond").click(function () {
        var radius = document.getElementById("poolLong2").value;
        var high = document.getElementById("poolHeight2").value;
        var volume2 = document.getElementById("poolVolume2");

        volume2.value = (Math.PI * radius * radius * high).toFixed(1);
    })
    //点击计算体积3
    $("#btn_anisePond").click(function () {
        var long = document.getElementById("poolLong3").value;
        var width = document.getElementById("poolWidth3").value;
        var height = document.getElementById("poolHeight3").value;
        var volume = document.getElementById("poolVolume3");

        volume.value = long * 8 * width * height;
    })

    $("#tableAjaxId").on("click", ".xiugai", function () {
        var id = $(this).attr("dataId");
        Form.clearValues($("#commonForm"));
        changePond(0);
        var radio = document.getElementsByName("pond");
        radio[0].checked = true;
        $("#squaresPondShow").find('[name]').each(function () {
            $(this).val('0');
        })
        $("#circlesPondShow").find('[name]').each(function () {
            $(this).val('0');
        })
        $("#anisePondShow").find('[name]').each(function () {
            $(this).val('0');
        })
        $("#xxid").val(id);
    })

    $("#infoSubmit").click(function () {
        var data = Form.getValues($("#commonForm"))
        if (pondStatus == 0) {
            data.pond = pondStatus
            data.poolLong = document.getElementById("poolLong").value;
            data.poolWidth = document.getElementById("poolWidth").value;
            data.poolHeight = document.getElementById("poolHeight").value;
            data.poolVolume = document.getElementById("poolVolume").value;
        } else if (pondStatus == 1) {
            data.pond = pondStatus
            data.poolLong = document.getElementById("poolLong2").value;
            data.poolWidth = 0;
            data.poolHeight = document.getElementById("poolHeight2").value;
            data.poolVolume = document.getElementById("poolVolume2").value;
        } else if (pondStatus == 2) {
            data.pond = pondStatus
            data.poolLong = document.getElementById("poolLong3").value;
            data.poolWidth = document.getElementById("poolWidth3").value;
            data.poolHeight = document.getElementById("poolHeight3").value;
            data.poolVolume = document.getElementById("poolVolume3").value;
        }
        Validator.builder()
            .dom($("#commonForm"))
            .customValidate(check)
            .customSubmit(function (e) {
                if (!e) {
                    return false;
                }
                Request.builder()
                    .url(STATION_UPDATE)
                    .data(data)
                    .isToken(true)
                    .callback(function (e) {
                        if (e.code === "00000") {
                            LayerUtil.successMsg(ERROR_MSG.SUCCESS)
                            setTimeout(function () {
                                $("#tableAjaxId").bootstrapTable('refresh', {pageNumber: 1});
                                $("#commonDiv").find(".close").trigger("click");
                            }, 1000)
                        } else {
                            LayerUtil.failMsg(e.msg != null ? e.msg : ERROR_MSG.FAIL)
                        }
                        $(".mx_validator_button").attr("disabled", false)
                    }).post();
            }, null).do()
    });

    $("#tableAjaxId").on("click", ".jiaozhun", function () {
        var id = $.trim($(this).attr("dataId"));
        var type = $.trim($(this).attr("dataType"));
        if (type === "1") {
            $("#jzmsg").html('<a style="font-weight: bold">是否设置该机器为校准机器? </a><a style="color: red;">(校准机器不会产生投喂记录,不能进行手动投喂和设置任务操作)</a>');
        } else if (type === "0") {
            $("#jzmsg").html('<a style="font-weight: bold">是否设置该机器为常规机器?</a>');
        } else {
            LayerUtil.failMsg("请刷新重试");
            return false;
        }
        if (!id) {
            LayerUtil.failMsg("请刷新重试");
            return false;
        }
        $("#setjz").attr("stationId", id);
        $("#setjz").attr("type", type);
    })

    $("#setjz").click(function () {
        var stationId = $.trim($("#setjz").attr("stationId"));
        if (!stationId) {
            LayerUtil.failMsg("请刷新重试");
            return false;
        }
        var type = $.trim($("#setjz").attr("type"));
        if (!type) {
            LayerUtil.failMsg("请刷新重试");
            return false;
        }
        Request.builder()
            .url(STATION_SET_JZ + "/" + stationId + "/" + type)
            .isToken(true)
            .callback(function (e) {
                if (e.code === "00000") {
                    LayerUtil.successMsg(ERROR_MSG.SUCCESS)
                    setTimeout(function () {
                        $("#tableAjaxId").bootstrapTable('refresh', {pageNumber: 1});
                        $("#jiaozhunDiv").find(".close").trigger("click");
                    }, 1000)
                } else {
                    LayerUtil.failMsg(e.msg != null ? e.msg : ERROR_MSG.FAIL)
                }
                $(".mx_validator_button").attr("disabled", false)
            }).post();
    })

    $(".startStation").click(function () {
        changeMode(1);
    })

    $(".stopStation").click(function () {
        changeMode(0);
    })

    $('#weekSave').click(function () {
        //获取checkBox的元素
        var weekIds = $("#weekChooseList").find('input[type=checkbox]');
        var data = '';
        weekIds.each(function () {
            //获取当前元素的勾选状态
            if ($(this).prop("checked")) {
                data = data + $(this)[0].labels[0].innerHTML + "，";
            }
        });
        if (!data) {
            return LayerUtil.failMsg("选择星期不能为空");
        }
        //去最后的点
        data = data.substring(0, data.length - 1);
        if (data.length === 20) {
            data = "每天";
        }
        var html = `<div class="popupDiv"  onmouseover="showPopupShowDiv()" onmouseout="clearPopupShowDiv()" type="button" dataType="${data}" data-toggle="modal" data-target="#weekChooseDiv">
                          ${data}
                      </div>
                    <div class="popupShowDiv" style="visibility: hidden;display: none;">${data}</div>`;
        $("#updateHtmlID").html(html);
        document.getElementById("updateHtmlID").removeAttribute("id");
        $("#weekChooseDiv").find(".close").trigger("click");
    })

    $("#tasks").on("click", ".popupDiv", function () {
        var dom = $(this).attr("dataType");
        var arr = dom.toString().split("，");
        $(this).parent().attr("id", "updateHtmlID");
        var html = ``
        if (arr.indexOf('每天') != -1) {
            html += monday + tuesday + wednesday + thursday + friday + saturday + sunday;
        } else {
            if (arr.indexOf('周一') != -1) {
                html += monday
            } else {
                html += noMonday
            }
            if (arr.indexOf('周二') != -1) {
                html += tuesday
            } else {
                html += noTuesday
            }
            if (arr.indexOf('周三') != -1) {
                html += wednesday
            } else {
                html += noWednesday
            }
            if (arr.indexOf('周四') != -1) {
                html += thursday
            } else {
                html += noThursday
            }
            if (arr.indexOf('周五') != -1) {
                html += friday
            } else {
                html += noFriday
            }
            if (arr.indexOf('周六') != -1) {
                html += saturday
            } else {
                html += noSaturday
            }
            if (arr.indexOf('周日') != -1) {
                html += sunday
            } else {
                html += noSunday
            }
        }
        $('#weekChooseList').html(html)
    })

    //添加一行
    $("#btn-add-task").click(function () {
        var html = html += '<tr>';
        //设置周
        html += '<td style="position: relative;text-align: center">';
        html += `<div class="popupDiv"  onmouseover="showPopupShowDiv()" onmouseout="clearPopupShowDiv()" type="button" dataType="每天" data-toggle="modal" data-target="#weekChooseDiv">
                                  每天
                              </div>
                            <div class="popupShowDiv" style="visibility: hidden;display: none;">每天</div>`
        html += '</td>';
        //设置小时
        html += '<td><select class="form-control input-sm">';
        $.each(hourJson, function (indexHour, itemHour) {
            if ("00" === itemHour) {
                html += '<option value="' + itemHour + '" selected>' + itemHour + '时</option>';
            } else {
                html += '<option value="' + itemHour + '">' + itemHour + '时</option>';
            }
        });
        html += '</select></td>';
        //设置分钟
        html += '<td><select class="form-control input-sm">';
        $.each(minJson, function (indexMin, itemMin) {
            if ("00" === itemMin) {
                html += '<option value="' + itemMin + '" selected>' + itemMin + '分</option>';
            } else {
                html += '<option value="' + itemMin + '">' + itemMin + '分</option>';
            }
        });
        html += '</select></td>';

        html += '<td>' +
            '<select class="form-control input-sm" id="speed">' +
            '<option value="normal" selected>低速模式</option>' +
            '<option value="high" >高速模式</option>' +
            '</select>' +
            '</td>' +
            '<td class="mx_validator">' +
            '<input type="text" placeholder="请输入投喂量" name="weight" class="form-control touchSpin mx_required mx_custom" mx_required_msg="投喂量不能为空">' +
            '</td>' +
            '<td><button class="btn btn-danger btn-del-task btn-sm"">删除</button></td>' +
            '</tr>';

        $("#tasks").append(html);
    })

    //删除一行
    $("#tasks").on("click", ".btn-del-task", function () {
        $(this).parent().parent().remove();
    })

    //点击批量设置任务
    $("#toSetTask").click(function () {
        var records = $("#tableAjaxId").bootstrapTable('getSelections');
        Form.clearValues($("#task_form"));
        $("#tasks").html(" ");
        if (records.length > 0) {
            for (var i in records) {
                ids[i] = records[i]["id"];
            }
        } else {
            LayerUtil.failMsg("请选择要设置任务的设备")
            return false;
        }
    })

    //保存任务
    $("#btn_upd_task").click(function () {
        var data = Form.getValues($("#task_form"))
        data.ids = ids;
        secsDate.map(item => {
            if (item.id == data.calibrationId) {
                fast = item.highSecs / 100
                slow = item.normalSecs / 100
            }
        })

        Validator.builder()
            .dom($("#task_form"))
            .customValidate(checkTaskForm)
            .customSubmit(function (e) {
                if (!e) {
                    return false;
                }
                var tasks = [];
                var hmmap = {};
                var timeDate = [];
                var flag = 0;
                $("#tasks tr").each(function () {
                    var weeks = $(this).find(".popupDiv");
                    var cols = $(this).find("select");
                    var vals = $(this).find("input");
                    var task = {};

                    var week = $(weeks[0]).html().trim();
                    var returnWeek = "";
                    if (week !== null) {
                        var arr = week.toString().split("，");
                        if (arr.length !== 7) {
                            if (arr.indexOf('每天') != -1) {
                                returnWeek += `1234567`
                            }
                            if (arr.indexOf('周一') != -1) {
                                returnWeek += `1`
                            }
                            if (arr.indexOf('周二') != -1) {
                                returnWeek += `2`
                            }
                            if (arr.indexOf('周三') != -1) {
                                returnWeek += `3`
                            }
                            if (arr.indexOf('周四') != -1) {
                                returnWeek += `4`
                            }
                            if (arr.indexOf('周五') != -1) {
                                returnWeek += `5`
                            }
                            if (arr.indexOf('周六') != -1) {
                                returnWeek += `6`
                            }
                            if (arr.indexOf('周日') != -1) {
                                returnWeek += `7`
                            }
                            returnWeek = returnWeek.replace(/(.{1})/g, "$1,"); // 在每两个字符后面添加逗号
                            //去最后的点
                            returnWeek = returnWeek.substring(0, returnWeek.length - 1);
                        }
                    } else {
                        returnWeek += "1,2,3,4,5,6,7";
                    }
                    var hour = $(cols[0]).val().trim();
                    var min = $(cols[1]).val().trim();
                    var speedMode = $(cols[2]).val().trim();
                    var weight = $(vals[0]).val().trim();
                    if (!hour || !min || !speedMode || !weight) {
                        LayerUtil.failMsg("所有项目都必填");
                        flag = 1;
                        return false;
                    }
                    task['week'] = returnWeek;
                    task['hour'] = hour;
                    task['min'] = min;
                    task['mode'] = speedMode;
                    task['weight'] = Number(weight);
                    var weekArr = returnWeek.toString().split(",");
                    $.each(weekArr, function (index, item) {
                        var timeKey = item + '_' + task['hour'] + '_' + task['min'];
                        if (!timeDate.includes(timeKey)) {
                            timeDate.push(timeKey);
                        } else {
                            LayerUtil.failMsg("时间段重复了,请检查");
                            flag = 1;
                            return false;
                        }
                    })
                    var key = task['week'] + '_' + task['hour'] + '_' + task['min'];
                    if (!hmmap[key]) {
                        hmmap[key] = true;
                        tasks.push(task);
                    }
                    if (tasks.length > 24) {
                        LayerUtil.failMsg("任务数量不能大于24个");
                        flag = 1;
                        return false;
                    }
                })
                var orderArr = sortObjectArray(tasks, ['hour', 'min'], "asc");
                setTimeout(() => {
                    data.tasks = JSON.stringify(orderArr);
                    if (flag === 0) {
                        Request.builder()
                            .url(STATION_BATCHSETTING)
                            .data(data)
                            .isToken(true)
                            .callback(function (e) {
                                if (e.code === "00000") {
                                    LayerUtil.successMsg(ERROR_MSG.SUCCESS)
                                    setTimeout(function () {
                                        $("#settaskDIV").find(".close").trigger("click");
                                        $("#tableAjaxId").bootstrapTable('refresh', {pageNumber: 1});
                                    }, 1000)
                                } else {
                                    LayerUtil.failMsg(e.msg != null ? e.msg : ERROR_MSG.FAIL)
                                }
                                $(".mx_validator_button").attr("disabled", false)
                            }).post();
                    }
                }, 10)
            }, null).do()
    })
});

//池子样式计算
function changePond(value) {
    if (value === 0) {
        squaresPondShow.style.display = "block";
        circlesPondShow.style.display = "none";
        anisePondShow.style.display = "none";
        pondStatus = 0
    } else if (value === 1) {
        squaresPondShow.style.display = "none";
        circlesPondShow.style.display = "block";
        anisePondShow.style.display = "none";
        pondStatus = 1
    } else if (value === 2) {
        squaresPondShow.style.display = "none";
        circlesPondShow.style.display = "none";
        anisePondShow.style.display = "block";
        pondStatus = 2
    }
}

function checkTaskForm(validatorDom) {
    var h = Number(validatorDom.parent().parent().find("td:eq(1)").children().val())
    var min = Number(validatorDom.parent().parent().find("td:eq(2)").children().val())
    var mode = validatorDom.parent().parent().find("td:eq(3)").children().val()
    var maxWeight
    if (mode == 'high') {
        maxWeight = Math.ceil(100 / fast * 32700)
    } else {
        maxWeight = Math.ceil(100 / slow * 32700)
    }
    var secs100 = mode == "normal" ? slow : fast;
    var secs = secs100 * validatorDom.val() / 100 / 60;
    var weight = Math.ceil((1380 - (h * 60 + min)) * 60 * 100 / secs100) - 1
    if (weight > maxWeight) {
        weight = maxWeight
    }
    if (h * 60 + min + secs < 60 || h * 60 + min + secs > 1380 || h == 0) {
        if (h != 0 && h != 23) {
            if (weight == maxWeight) {
                return {
                    "retBool": true,
                    "msg": "超出最大投喂时间" + "(" + "推荐投喂：" + weight + "g)"
                };
            } else {
                return {
                    "retBool": true,
                    "msg": "投喂结束时间处于系统维护期间" + "(" + "推荐投喂：" + weight + "g)"
                };
            }
        } else {
            return {
                "retBool": true,
                "msg": "投喂时间处于系统维护期间"
            };
        }
    }
    if (validatorDom.val() > maxWeight) {
        return {
            "retBool": true,
            "msg": "超出最大投喂时间" + "(" + "推荐投喂：" + weight + "g)"
        };
    }
    if (validatorDom.attr("name") === "weight" && validatorDom.val() < 0.00001) {
        return {
            "retBool": true,
            "msg": "投喂量必须大于0"
        };
    }
}

//切换模式
function changeMode(mode) {
    ids = [];
    var records = $("#tableAjaxId").bootstrapTable('getSelections');
    if (records.length > 0) {
        for (var i in records) {
            ids[i] = records[i]["id"];
        }
    } else {
        if (mode === 0) {
            LayerUtil.failMsg("请选择要停止的设备！")
            return false;
        } else if (mode === 1) {
            LayerUtil.failMsg("请选择要启动的设备!")
            return false;
        }
    }
    var lock = false;
    var confirm = LayerUtil.confirm("确认变更模式?", function () {
        if (!lock) {
            lock = true;
            Request.builder()
                .url(STATION_BATCH)
                .data({"ids": ids, "mode": mode})
                .isToken(true)
                .callback(function (e) {
                    if (e.code === "00000") {
                        ids = [];
                        LayerUtil.successMsg("指令已发出,请刷新页面查看结果~")
                    } else {
                        LayerUtil.failMsg(e.msg != null ? e.msg : ERROR_MSG.FAIL)
                    }
                }).post();
            layer.close(confirm);
        }
    }, null)
}

function showPopupShowDiv() {
    var innerHTML = $.trim(event.srcElement.innerHTML);
    if (innerHTML.length > 8) {
        var div = event.srcElement;
        var showDiv = div.parentElement.childNodes;
        showDiv[1].nextSibling.style.display = "block";
    }
    if (event && event.srcElement && event.srcElement.className == "popupDiv") {
        var div = event.srcElement;
        var showDiv = div.parentElement.childNodes;
        showDiv[1].nextSibling.style.visibility = "visible";
    }
}

function clearPopupShowDiv() {
    if (event && event.srcElement && event.srcElement.className == "popupDiv") {
        var div = event.srcElement;
        var showDiv = div.parentElement.childNodes;
        showDiv[1].nextSibling.style.visibility = "hidden";
    }
}

function checkedoption(value, row, index) {
    var cancel = row.cancel;
    if (cancel === 0) {
        return {disabled: false}
    } else {
        return {disabled: true}
    }
}

columns = [{
    checkbox: true,
    align: 'center',
    formatter: checkedoption
}, {
    field: 'code',
    title: '设备代码',
    align: 'center',
    valign: 'middle',
    sortable: true,
}, {
    field: 'name',
    title: '设备(养殖池)名称',
    align: 'center',
    valign: 'middle',
    sortable: true,
}, {
    field: 'workshopName',
    title: '车间名称',
    align: 'center',
    valign: 'middle',
    sortable: true,
}, {
    field: 'speciesName',
    title: '养殖物种',
    align: 'center',
    valign: 'middle'
}, {
    field: 'typeName',
    title: '设备类型',
    align: 'center',
    valign: 'middle'
}, {
    field: 'version',
    title: '设备版本',
    align: 'center',
    valign: 'middle',
    formatter: function (value, row, index) {
        return "V" + value;
    }
}, {
    field: 'type',
    title: '类型',
    align: 'center',
    valign: 'middle',
    formatter: function (value, row, index) {
        if (value === 0) {
            return "常规机器";
        } else if (value === 1) {
            return "校准机器";
        } else {
            return "未知";
        }
    }
}, {
    field: 'status',
    title: '网络状态',
    align: 'center',
    valign: 'middle',
    sortable: true,
    formatter: function (value, row, index) {
        if (value === 0) {
            return "<span style='color:#ffffff;background-color: #73CDAA;padding: 0 5px;border-radius: 0.25rem;'>在线</span>";
        } else if (value === 1) {
            return "<span style='color:#ffffff;background-color: #cccccc;padding: 0 5px;border-radius: 0.25rem;'>离线</span>";
        } else {
            return "未知";
        }
    }
}, {
    field: 'stopStatus',
    title: '运行状态',
    align: 'center',
    valign: 'middle',
    sortable: true,
    formatter: function (value, row, index) {
        if (value === 0) {
            return "<span style='color:#ffffff;background-color: #73CDAA;padding: 0 5px;border-radius: 0.25rem;'>运行</span>";
        } else if (value === 1) {
            return "<span style='color:#ffffff;background-color: #ed5565;padding: 0 5px;border-radius: 0.25rem;'>停止</span>";
        } else {
            return "未知";
        }
    }
}, {
    field: 'mode',
    title: '工作模式',
    align: 'center',
    valign: 'middle',
    formatter: function (value, row, index) {
        if (value === 0) {
            return "<span style='color:#ffffff;background-color: #1c84c6;padding: 0 5px;border-radius: 0.25rem;'>手动模式</span>";
        } else if (value === 1) {
            return "<span style='color:#ffffff;background-color: #73CDAA;padding: 0 5px;border-radius: 0.25rem;'>自动模式</span>";
        } else if (value === 2) {
            return "<span style='color:#ffffff;background-color: #800080;padding: 0 5px;border-radius: 0.25rem;'>调试模式</span>";
        } else {
            return "未知";
        }
    }
}, {
    field: 'cancel',
    title: '设备状态',
    align: 'center',
    valign: 'middle',
    formatter: function (value, row, index) {
        if (value === 0) {
            return "<span style='color:#ffffff;background-color: #1c84c6;padding: 0 5px;border-radius: 0.25rem;'>正常</span>";
        } else if (value === 1) {
            return "<span style='color:#ffffff;background-color: red;padding: 0 5px;border-radius: 0.25rem;'>作废</span>";
        } else {
            return "未知";
        }
    }
}, {
    field: 'lastModifyTime',
    title: '最后修改时间',
    align: 'center',
    valign: 'middle',
    sortable: true,
    formatter: function (value, row, index) {
        return DateUtil.changeDateToString(value, DateFormatEnum.YYYY_MM_DD_HH_MM);
    }
}, {
    field: 'lastResponseTime',
    title: '最后通讯时间',
    align: 'center',
    valign: 'middle',
    formatter: function (value, row, index) {
        return DateUtil.changeDateToString(value, DateFormatEnum.YYYY_MM_DD_HH_MM);
    }
}, {
    title: "操作",
    align: 'center',
    valign: 'middle',
    width: 160,
    formatter: option
}]


function option(value, row, index) {
    var html = '<div class="d-flex justify-content-center">';
    if (row.workshopName == null || row.workshopName === "" ||
        row.speciesName == null || row.speciesName === "" ||
        row.typeName == null || row.typeName === "") {
        html += '<a class="btn btn-xs btn-default btn_dif_function xiugai" data-toggle="modal" data-target="#commonDiv" dataId="' +
            row.id + '" title="完善资料" >完善资料</a>';
    } else {
        if (row.cancel === 0) {
            html += ' <a class="btn btn-xs btn-default m-r-5" target="_blank" href="/admin/station/detail.html?id=' + row
                .id + '" title="详情" >详情</a>';
            if (row.type === 0) {
                html +=
                    '<a class="btn btn-xs btn-default jiaozhun bg1" data-toggle="modal" data-target="#jiaozhunDiv" dataType="1" dataId="' +
                    row.id + '" title="校准机器" >设为校准机器</a>';
            } else if (row.type === 1) {
                html +=
                    '<a class="btn btn-xs btn-default jiaozhun bg" data-toggle="modal" data-target="#jiaozhunDiv" dataType="0" dataId="' +
                    row.id + '" title="常规机器" >设为常规机器</a>';
            }
        } else {
            html += ' <a class="btn btn-xs btn-default" target="_blank" href="/admin/station/detail_cancel.html?id=' + row.id + '" title="详情" >详情</a>';
        }
    }
    html += '</div>'
    return html;
}
